package org.example.leetcode.core.controller;

import org.example.leetcode.common._enum.BaseEnum;
import org.example.leetcode.common._enum.DifficultyEnum;
import org.example.leetcode.common._enum.EnumDto;
import org.example.leetcode.common.pojo.GlobalResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/enum")
public class EnumController {
    @GetMapping("/{enumName}")
    public GlobalResponse<List<EnumDto>> getEnum(@PathVariable("enumName")String enumName) throws ClassNotFoundException {
        Class<?> aClass = Class.forName("org.example.leetcode.common._enum."+enumName);
        Object[] enumConstants = aClass.getEnumConstants();
        List<EnumDto> res=new ArrayList<>();
        for(Object _enum:enumConstants){
            EnumDto enumDto = new EnumDto();
            if(_enum instanceof BaseEnum){
                BaseEnum<?,?> baseEnum=(BaseEnum<?,?>) _enum;
                enumDto.setCode(baseEnum.getCode());
                enumDto.setName(baseEnum.getName());
                res.add(enumDto);
            }
        }
        return GlobalResponse.success(res);
    }
    @GetMapping("/difficulty")
    public GlobalResponse<List<DifficultyEnum.DifficultyEnumDto>> getAllDifficult(){
        List<DifficultyEnum.DifficultyEnumDto> res=new ArrayList<>();
        for (DifficultyEnum value : DifficultyEnum.values()) {
            DifficultyEnum.DifficultyEnumDto difficultyEnumDto = new DifficultyEnum.DifficultyEnumDto();
            difficultyEnumDto.setCode(value.getCode());
            difficultyEnumDto.setColor(value.getColor());
            difficultyEnumDto.setScore(value.getScore());
            difficultyEnumDto.setName(value.getName());
            res.add(difficultyEnumDto);
        }
        return GlobalResponse.success(res);
    }
}
